package com.acme.bankapp.domain.bank;

import com.acme.exceptions.OverDraftLimitExceededException;

@SuppressWarnings("serial")
public class CheckingAccount extends AbstractAccount {
	private double overdraft;

	public CheckingAccount(double balance, double overdraft) {
		super(balance);
		if (overdraft < 0) {
			throw new IllegalArgumentException();
		}
		this.overdraft = overdraft;
	}

	@Override
	public String toString() {
		return "CheckingAccount [id = " + getId() + ", overdraft=" + overdraft
				+ ", balance=" + getBalance() + "]";
	}

	@Override
	public double getMaximumAmountToWithdraw() {
		return getBalance() + overdraft;
	}

	@Override
	public void withdraw(double amount) throws OverDraftLimitExceededException {
		if (amount < 0) {
			throw new IllegalArgumentException();
		}

		if (amount >= getBalance() + overdraft) {
			throw new OverDraftLimitExceededException(amount, this,
					getMaximumAmountToWithdraw());
		}
		setBalance(getBalance() - amount);
		assert (overdraft >= 0);
		assert (getMaximumAmountToWithdraw() >= 0);
	}

	@Override
	public void deposit(double amount) {
		if (amount < 0) {
			throw new IllegalArgumentException();
		}
		setBalance(getBalance() + amount);
	}

}
